package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.MethodVisitor;

/**
 * Classe que implementa o numero total de metodos finais.
 * @author Rodrigo
 *
 */

public class NumberOfFinalMethods extends Measure{

	private double value;
	
	public NumberOfFinalMethods() {
		super();
		value = 0d;
		addApplicableGranularity(Granularity.CLASS);
	}

	@Override
	public String getName() {
		return "Number of Final Methods";
	}

	@Override
	public String getAcronym() {
		return "NFM";
	}

	@Override
	public String getDescription() {
		return "Return the number of final methods in a class";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	/**
	 * Return the maximum value
	 * @return -1 if this measure doesn't have a maximum value (infinity value)
	 */
	@Override
	public double getMaxValue() {
		return -1;
	}

	/**
	 * Return the reference value
	 * @return -1 if this measure doesn't have a reference value 
	 */
	@Override
	public double getRefValue() {
		return 0;
	}

	@Override
	public <T> void measure(T unit) {
		
		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		MethodVisitor visitor = new MethodVisitor();
		parse.accept(visitor);

		setCalculatedValue(getAllStaticMethods(visitor));
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value;
	}
	
	public int getAllStaticMethods(MethodVisitor visitor){
		 return visitor.getNumberOfFinalMethods();
	}
	
}
